package com.aion.jirc.gui;

import javax.swing.JButton;
import javax.swing.JToolBar;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * Date: 11-01-29
 * Time: 15:10
 *
 * @author Aion
 */
public class Switchbar extends JToolBar {

    private static final HashMap<String, JButton> BUTTONS = new HashMap<String, JButton>();

    private ActionListener listener;

    protected Switchbar(ActionListener listener) {
        super();
        this.listener = listener;
    }

    public void addButton(String text) {
        if (text == null || text.isEmpty()) {
            return;
        }
        JButton button = new JButton(text);
        button.setActionCommand("Switchbar.button");
        button.addActionListener(listener);
        BUTTONS.put(text, button);
        add(button);
    }

    public void removeButton(String text) {
        if (text == null || text.isEmpty()) {
            return;
        }
        System.out.println("remove " + text);
        remove(BUTTONS.get(text));
        repaint();
    }

}
